package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.UserOrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import com.sky.vo.OrderandDrtaill;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/user/order")
@RestController
@Slf4j
public class UserOrderController {
    @Autowired
    private UserOrderService userOrderService;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> add(@RequestBody OrdersSubmitDTO submitDTO) {
        OrderSubmitVO orderSubmitVO = userOrderService.addOrder(submitDTO);
        System.out.println(orderSubmitVO);
        return Result.success(orderSubmitVO);

    }

    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO1 = new OrderPaymentVO();
        OrderPaymentVO orderPaymentVO = userOrderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> details(@PathVariable("id") Long id) {
        OrderVO orderVO = userOrderService.getOrderId(id);
        return Result.success(orderVO);
    }


    @GetMapping("/historyOrders")
    public Result<PageResult> page(int page, int pageSize, Integer status) {
        PageResult pageResult = userOrderService.pageQuery4User(page, pageSize, status);
        return Result.success(pageResult);
    }
    @PutMapping("/cancel/{id}")
    @ApiOperation("取消订单")
    public Result cancel(@PathVariable("id") Long id) throws Exception {
        userOrderService.userCancelById(id);
        return Result.success();
    }
    @PostMapping("/repetition/{id}")
    @ApiOperation("再来一单")
    public Result repetition(@PathVariable Long id) {
        userOrderService.repetition(id);
        return Result.success();
    }

@GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        userOrderService.reminder(id);
        return Result.success();
}

}
